package ui.panel;

import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.paint.Paint;
import javafx.stage.StageStyle;
import javafx.util.Duration;
import ui.MySystemTray;
import ui.Window;

import java.awt.*;
import java.io.IOException;
import java.net.URL;

public class SetUp extends Window {

    public SetUp() throws IOException, AWTException {
        URL resource = getClass().getResource("/fxml/SetUp.fxml");
        root = FXMLLoader.load(resource);

        Scene scene = new Scene(root, 815, 497);
        scene.setFill(Paint.valueOf("#ffffff00"));

        MySystemTray.getInstance().listen(this);

        initStyle(StageStyle.TRANSPARENT);
        setScene(scene);
        setTitle("IceoLogy壁纸");

        ((Button) $("close")).setTooltip(new Tooltip("关闭"));
        ((Button) $("mini")).setTooltip(new Tooltip("最小化"));
        //设置提示延迟出现时间
        ((Button) $("close")).getTooltip().setShowDelay(Duration.millis(200));
        ((Button) $("mini")).getTooltip().setShowDelay(Duration.millis(200));
        move();
        close1();
        mini();
        setIcon();
    }

    /**
     * 关闭和最小化
     */
    public void close1() {
        ((Button) $("close")).setOnAction(event -> {
            this.close();
        });
    }


    public void mini() {
        ((Button) $("mini")).setOnAction(event -> {
            setIconified(true);
        });
    }


    /**
     * 设置错误提示
     *
     * @param id
     * @param Text
     */
    public void setErrorTip(String id, String Text) {
        ((Label) $(id)).setText(Text);
    }


    public void clear(String id) {
        ((TextField) $(id)).clear();
    }


}
